/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

package org.erossi.pigest.web.soggetto;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.erossi.pigest.model.soggetto.Soggetto;
import org.springframework.web.servlet.view.document.AbstractExcelView;

/**
 * 'ListaSoggettiHSSFView' class: classe che costituisce la vista per la versione HSSF
 *   della lista soggetti.
 *
 * @author erossi
 * @version Sep 23, 2008
 */
public class ListaSoggettiHSSFView extends AbstractExcelView {
  
  @Override
  @SuppressWarnings("unchecked")
  protected void buildExcelDocument(Map model, HSSFWorkbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception {

    HSSFSheet sheet_0 = workbook.createSheet(this.getApplicationContext().getMessage("bean.subjects", null, request.getLocale()));

    HSSFRow row_0 = sheet_0.createRow(0);

    HSSFCell cell_r0c0 = row_0.createCell((short) 0);
    cell_r0c0.setCellValue(this.getApplicationContext().getMessage("bean.subjects.id", null, request.getLocale()));
    HSSFCell cell_r0c1 = row_0.createCell((short) 1);
    cell_r0c1.setCellValue(this.getApplicationContext().getMessage("bean.subjects.version", null, request.getLocale()));
    HSSFCell cell_r0c2 = row_0.createCell((short) 2);
    cell_r0c2.setCellValue(this.getApplicationContext().getMessage("bean.subjects.family_name", null, request.getLocale()));
    HSSFCell cell_r0c3 = row_0.createCell((short) 3);
    cell_r0c3.setCellValue(this.getApplicationContext().getMessage("bean.subjects.name", null, request.getLocale()));
    HSSFCell cell_r0c4 = row_0.createCell((short) 4);
    cell_r0c4.setCellValue(this.getApplicationContext().getMessage("bean.subjects.company_name", null, request.getLocale()));
    HSSFCell cell_r0c5 = row_0.createCell((short) 5);
    cell_r0c5.setCellValue(this.getApplicationContext().getMessage("bean.subjects.vat_code", null, request.getLocale()));
    HSSFCell cell_r0c6 = row_0.createCell((short) 6);
    cell_r0c6.setCellValue(this.getApplicationContext().getMessage("bean.subjects.tax_code", null, request.getLocale()));
    HSSFCell cell_r0c7 = row_0.createCell((short) 7);
    cell_r0c7.setCellValue(this.getApplicationContext().getMessage("bean.subjects.address", null, request.getLocale()));
    HSSFCell cell_r0c8 = row_0.createCell((short) 8);
    cell_r0c8.setCellValue(this.getApplicationContext().getMessage("bean.subjects.city", null, request.getLocale()));
    HSSFCell cell_r0c9 = row_0.createCell((short) 9);
    cell_r0c9.setCellValue(this.getApplicationContext().getMessage("bean.subjects.zip", null, request.getLocale()));
    HSSFCell cell_r0c10 = row_0.createCell((short) 10);
    cell_r0c10.setCellValue(this.getApplicationContext().getMessage("bean.subjects.province", null, request.getLocale()));
    HSSFCell cell_r0c11 = row_0.createCell((short) 11);
    cell_r0c11.setCellValue(this.getApplicationContext().getMessage("bean.subjects.phone", null, request.getLocale()));
    HSSFCell cell_r0c12 = row_0.createCell((short) 12);
    cell_r0c12.setCellValue(this.getApplicationContext().getMessage("bean.subjects.fax", null, request.getLocale()));
    HSSFCell cell_r0c13 = row_0.createCell((short) 13);
    cell_r0c13.setCellValue(this.getApplicationContext().getMessage("bean.subjects.email", null, request.getLocale()));
    HSSFCell cell_r0c14 = row_0.createCell((short) 14);
    cell_r0c14.setCellValue(this.getApplicationContext().getMessage("bean.subjects.web", null, request.getLocale()));
    
    List<Soggetto> soggetti = (List<Soggetto>) model.get("listaSoggetti");
    
    if (soggetti != null) {
    
      for (int i = 0; i < soggetti.size(); i++) {
        
        Soggetto soggetto_i = soggetti.get(i);
        
        HSSFRow row_i = sheet_0.createRow(i + 1);
        
        HSSFCell cell_rIc0 = row_i.createCell((short) 0);
        Long id = soggetto_i.getId();
        if (id != null) {cell_rIc0.setCellValue(id);}
        
        HSSFCell cell_rIc1 = row_i.createCell((short) 1);
        Long version = soggetto_i.getVersion();
        if (version != null) {cell_rIc1.setCellValue(version);}
        
        HSSFCell cell_rIc2 = row_i.createCell((short) 2);
        String cognome = soggetto_i.getCognome();
        if (cognome != null) {cell_rIc2.setCellValue(cognome);}
        
        HSSFCell cell_rIc3 = row_i.createCell((short) 3);
        String nome = soggetto_i.getNome();
        if (nome != null) {cell_rIc3.setCellValue(nome);}        
        
        HSSFCell cell_rIc4 = row_i.createCell((short) 4);
        String ragioneSociale = soggetto_i.getRagioneSociale();
        if (ragioneSociale != null) {cell_rIc4.setCellValue(ragioneSociale);}
        
        HSSFCell cell_rIc5 = row_i.createCell((short) 5);
        String partitaIVA = soggetto_i.getPartitaIVA();
        if (partitaIVA != null) {cell_rIc5.setCellValue(partitaIVA);}    
        
        HSSFCell cell_rIc6 = row_i.createCell((short) 6);
        String codiceFiscale = soggetto_i.getCodiceFiscale();
        if (codiceFiscale != null) {cell_rIc6.setCellValue(codiceFiscale);}   
        
        HSSFCell cell_rIc7 = row_i.createCell((short) 7);
        String indirizzo = soggetto_i.getIndirizzo();
        if (indirizzo != null) {cell_rIc7.setCellValue(indirizzo);}   
        
        HSSFCell cell_rIc8 = row_i.createCell((short) 8);
        String citta = soggetto_i.getCitta();
        if (citta != null) {cell_rIc8.setCellValue(citta);}   
        
        HSSFCell cell_rIc9 = row_i.createCell((short) 9);
        Integer CAP = soggetto_i.getCAP();
        if (CAP != null) {cell_rIc9.setCellValue(CAP);}   
        
        HSSFCell cell_rIc10 = row_i.createCell((short) 10);
        String provincia = soggetto_i.getProvincia();
        if (provincia != null) {cell_rIc10.setCellValue(provincia);}    
        
        HSSFCell cell_rIc11 = row_i.createCell((short) 11);
        String telefono = soggetto_i.getTelefono();
        if (telefono != null) {cell_rIc11.setCellValue(telefono);}   
        
        HSSFCell cell_rIc12 = row_i.createCell((short) 12);
        String fax = soggetto_i.getFax();
        if (fax != null) {cell_rIc12.setCellValue(fax);}   
        
        HSSFCell cell_rIc13 = row_i.createCell((short) 13);
        String email = soggetto_i.getEmail();
        if (email != null) {cell_rIc13.setCellValue(email);}   
        
        HSSFCell cell_rIc14 = row_i.createCell((short) 14);
        String web = soggetto_i.getWeb();
        if (web != null) {cell_rIc14.setCellValue(web);}   
        
      }
    
    }
    
  }
  
}

